import CURDHelper from '@/utils/CURDHelper'
import PageConfig from '@/utils/pageConfig'
import { getBtnCtr } from '@/utils/BtnControl'
import Query from '@/components/Query';
import XEUtils from 'xe-utils';
export default {
  name: 'CustomerResume',
  components: {
    Query
  },
  data() {
    return {
      QueryParams: {
        SupplierName: undefined
      },
      componentSize: PageConfig.ComponentSize,
      duration: PageConfig.Duration,
      btnPromission: '',
      editModal: false,
      QueryConditions: [],
      BaseApiUrl: '/api/Xmjcqdxx',
      SupplierSelectedRow:undefined,
      LeftGridOptions: {
        id: 'SupplierResume_LeftGrid',
        border: true,
        stripe: true,
        loading: false,
        size: PageConfig.ComponentSize,
        height: 750,
        rowConfig: {
          isHover: true,
          isCurrent: true
        },
        checkboxConfig: {
          highlight: true,
          range: true
        },
        columns: [
          { field: 'qdmc', title: '渠道名称', width: 248, showOverflow: true }
        ],
        data: []
      },
      MainGridOptions: {
        id: 'SupplierResume_MainGrid',
        border: true,
        stripe: true,
        loading: false,
        size: PageConfig.ComponentSize,
        height: 750,
        rowConfig: {
          isHover: true,
          isCurrent: true
        },
        checkboxConfig: {
          highlight: true,
          range: true
        },
        columns: [
          { field: 'qdmc', title: '渠道名称', minWidth: 150, showOverflow: true },
          { field: 'txmc', title: '体系名称', minWidth: 150, showOverflow: true },
          { field: 'shlx', title: '审核类型', minWidth: 150, showOverflow: true },
          { field: 'erpbh', title: '合同号', minWidth: 100, showOverflow: true },
          { field: 'kzxm', title: '开支款项', minWidth: 100, showOverflow: true },
          { field: 'kzlx', title: '开支类型', minWidth: 90, showOverflow: true },
          { field: 'kzje', title: '开支金额', minWidth: 90, showOverflow: true },
          { field: 'kzzt', title: '支付状态', minWidth: 90, showOverflow: true ,slots:{default:'kzStatus'}},
          { field: 'kzsj', title: '开支时间', minWidth: 120, showOverflow: true ,
            formatter: ({cellValue}) => XEUtils.toDateString(cellValue,'yyyy-MM-dd')},
          { field: 'skyh', title: '收款银行', minWidth: 150, showOverflow: true },
          { field: 'skzh', title: '收款账号', minWidth: 150, showOverflow: true },
          { field: 'skhm', title: '收款户名', minWidth: 150, showOverflow: true },
          { field: 'bz', title: '备注', minWidth: 150, showOverflow: true }
        ],
        data: []
      },
    }
  },
  created() {
    // 动态头部按钮
    this.btnPromission = getBtnCtr(
      this.$route.path,
      this.$store.getters.userPermission
    )
  },
  methods: {
    handleQuery() {
      this.QueryConditions = [];
      if (this.QueryParams.SupplierName) {
        this.QueryConditions.push({
          column: 'qdmc',
          condition: '6',
          content: this.QueryParams.SupplierName
        })
      }
      this.DoQuery(this.QueryConditions);
    },
    handleLeftGridCellClick({row}){
      this.SupplierSelectedRow = row;
      this.DoQueryExpenses();
    },
    DoQuery(e) {
      let request = {
        isPaging: false,
        pageSize: 1,
        pageIndex: 1,
        queryConditions: e,
        orderByConditions: []
      }
      CURDHelper.Query(request, this.BaseApiUrl)
        .then(res => {
          this.LeftGridOptions.data = res.data;
        }).catch(err => {
          VxeUI.modal.message({ content: `${err}`, status: 'error', duration: this.duration })
        })
    },
    DoQueryExpenses() {
      let request = {
        isPaging: false,
        pageSize: 1,
        pageIndex: 1,
        queryConditions: [{
          column:'t.qdid',
          condition:'0',
          content:this.SupplierSelectedRow.id
        }],
        orderByConditions: []
      }
      CURDHelper.Query(request, `${this.BaseApiUrl}\\GetExpensesData`)
        .then(res => {
          this.MainGridOptions.data = res.data;
        }).catch(err => {
          VxeUI.modal.message({ content: `${err}`, status: 'error', duration: this.duration })
        })
    },
  }
}
